﻿using System;
using System.Web;
using System.Web.Security;
using System.Text;
using System.Collections.Specialized;

namespace TeamFranceTriple
{
    public partial class Connexion : BaseUserControl
    {
        public string UserAddressIp { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["returnurl"] != null)
                RegisterHyperLink.NavigateUrl = String.Format("~/{0}/register/?returnurl=", ThisMaster.Requester.Culture, Request.QueryString["returnurl"]);
            else
                RegisterHyperLink.NavigateUrl = String.Format("~/{0}/register", ThisMaster.Requester.Culture);
        }

        protected void LoginUser_OnLoggedIn(object sender, EventArgs e)
        {
            FormsAuthentication.SetAuthCookie(LoginUser.UserName, true /* createPersistentCookie */);

            //L'utilisateur est maintenant authentifié
            if (Session["AnonymousID"] != null)
                Session["AnonymousID"] = null;
            
            if (Request.QueryString["returnurl"] != null)
                Response.Redirect(Request.QueryString["returnurl"]);
        }

        protected void PasswordRecoveryButton_OnClick(object sender, EventArgs e)
        {
            Response.Redirect(String.Format("~/{0}/pwdrecovery", ThisMaster.Requester.Culture));
        }
    }
}
